package com.complex.spring.advance.aop.proxy.sample;

import java.lang.reflect.Proxy;

/**
 * 动态代理
 * 只能作用于实现了某个interface的类使用(ISubject,IRequestable)
 * @author gao
 * 
 */
public class ProxyRunner {
	public static void main(String[] args) {
		
		//动态代理产生ISubject instance
		ISubject subject = (ISubject)Proxy.newProxyInstance(ProxyRunner.class
				.getClassLoader(), new Class[] { ISubject.class },
				new RequestCtrlInvocationHandler(new SubjectImpl()));
		subject.request();
		
		//动态代理产生IRequestable instance
		IRequestable requestable = (IRequestable)Proxy.newProxyInstance(ProxyRunner.class
				.getClassLoader(), new Class[] { IRequestable.class },
				new RequestCtrlInvocationHandler(new RequestableImpl()));
		requestable.request();
	}
}
